package cn.darkhorse.mesadmin.controller.ticket;


import cn.darkhorse.ticket.store.dto.TicketWarehousing2DTO;
import cn.darkhorse.ticket.store.dto.TicketWarehousingDTO;
import cn.darkhorse.ticket.store.service.TicketWarehousingService;
import cn.darkhorse.ticket.store.vo.TicketWarehousingVO;
import cn.darkhorse.ticket.store.vo.TicketWarehousingViewVO;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 入库主表 前端控制器
 * </p>
 *
 * @author wangxinghui
 * @since 2024-01-16
 */
@RestController
	@RequestMapping("/ticket/ticketWarehousing")
public class TicketWarehousingController extends BaseController{
	
	@Resource
	private TicketWarehousingService warehousingService;
	
	/**
	 * 列表
	 * @param code
	 * @param name
	 * @param beginTime
	 * @param endTime
	 * @return
	 */
	@RequestMapping(value = "/list",method = RequestMethod.GET)
	public TableDataInfo list(String code, String name, String beginTime, String endTime){
		startPage();
		List<TicketWarehousingVO> list = warehousingService.list(code, name, beginTime, endTime);
		return getDataTable(list);
	}
	
	/**
	 * 新增
	 * @param warehousingDTO
	 * @return
	 */
	@RepeatSubmit()
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	public AjaxResult add(@RequestBody TicketWarehousingDTO warehousingDTO){
		warehousingDTO.setFounder(SecurityUtils.getUserId());
		String s = warehousingService.add(warehousingDTO);
		return AjaxResult.success(s);
	}
	
	
	/**
	 * 修改
	 * @param warehousingDTO
	 * @return
	 */
	@RepeatSubmit()
	@RequestMapping(value = "/modify",method = RequestMethod.POST)
	public AjaxResult modify(@RequestBody TicketWarehousing2DTO warehousingDTO){
		warehousingDTO.setReviser(SecurityUtils.getUserId());
		warehousingDTO.setModifyTime(LocalDateTime.now());
		warehousingService.modify(warehousingDTO);
		return AjaxResult.success();
	}
	
	/**
	 * 查看
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/view",method = RequestMethod.GET)
	public AjaxResult add(Long id){
		if(null == id){
			return AjaxResult.success();
		}
		TicketWarehousingViewVO vo = warehousingService.view(id);
		return AjaxResult.success(vo);
	}
	
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@RepeatSubmit(interval = 2000)
	@RequestMapping(value = "/delete",method = RequestMethod.POST)
	public AjaxResult delete(Long id){
		if(null == id){
			return AjaxResult.success();
		}
		warehousingService.delete(id);
		return AjaxResult.success();
	}
	
	/**
	 * 是否能够删除
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/is-quote",method = RequestMethod.GET)
	public AjaxResult isCanBe(Long id){
		if(null == id){
			return AjaxResult.success();
		}
		warehousingService.isCanBe(id);
		return AjaxResult.success();
	}
	
	
}

